package cel;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that WayFarer rotates it's radar to scan for enemies.
 * 
 * @author Professor Elmar Carillo
 */
public class TestWayFarerTurnRadar extends RobotTestBed {
  /** True if the robot turns its radar during the test case. */
  boolean turnRadar = false;
  /** False if the robot is at any other turn besides the first turn. */
  boolean firstRadar = true;
  // The previous heading of the robot's radar.
  double previousRadar;

  /**
   * Specifies that SittingDuck and WayFarer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,cel.WayFarer";
  }

  /**
   * This test runs for 10 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if the radar is at a different heading.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot daCruzer
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

    // See if the heading of the radar of the robot is different at every turn.
    if (firstRadar) {
      firstRadar = false;
    }
    else {
      if (robot.getRadarHeading() != previousRadar) {
        turnRadar = true;
      }
    }
    previousRadar = robot.getRadarHeading();
  }

  /**
   * After the battle, check to see if the robot hit a wall.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check turnRadar", turnRadar);
  }
}
